/**
 * 智慧社区管理系统 - 移动端停车管理API接口
 * @author Wu.Liang
 * @date 2025-01-21
 * @description 移动端工程位于smart-community-app文件夹，严格遵循架构总览中的项目结构规范
 */

import request from './request'

// 停车状态管理API
export const parkingStatusApi = {
  // 获取停车状态
  getParkingStatus: () => {
    return request.get('/api/parking/status')
  },

  // 更新停车状态
  updateParkingStatus: (data) => {
    return request.put('/api/parking/status', data)
  },

  // 获取车位统计
  getSpaceStatistics: () => {
    return request.get('/api/parking/spaces/statistics')
  }
}

// 车位管理API
export const spaceApi = {
  // 分页查询车位列表
  getSpaceList: (params) => {
    return request.get('/api/parking/spaces', { params })
  },

  // 获取车位详情
  getSpaceDetail: (spaceId) => {
    return request.get(`/api/parking/spaces/${spaceId}`)
  },

  // 查询可用车位
  getAvailableSpaces: (params) => {
    return request.get('/api/parking/spaces/available', { params })
  },

  // 预约车位
  reserveSpace: (spaceId, data) => {
    return request.post(`/api/parking/spaces/${spaceId}/reserve`, data)
  },

  // 取消预约
  cancelReservation: (reservationId) => {
    return request.delete(`/api/parking/reservations/${reservationId}`)
  },

  // 获取我的预约
  getMyReservations: (params) => {
    return request.get('/api/parking/reservations/my', { params })
  }
}

// 车辆管理API
export const vehicleApi = {
  // 分页查询我的车辆
  getMyVehicles: (params) => {
    return request.get('/api/parking/vehicles/my', { params })
  },

  // 获取车辆详情
  getVehicleDetail: (vehicleId) => {
    return request.get(`/api/parking/vehicles/${vehicleId}`)
  },

  // 添加车辆
  addVehicle: (data) => {
    return request.post('/api/parking/vehicles', data)
  },

  // 更新车辆信息
  updateVehicle: (vehicleId, data) => {
    return request.put(`/api/parking/vehicles/${vehicleId}`, data)
  },

  // 删除车辆
  deleteVehicle: (vehicleId) => {
    return request.delete(`/api/parking/vehicles/${vehicleId}`)
  },

  // 设置默认车辆
  setDefaultVehicle: (vehicleId) => {
    return request.post(`/api/parking/vehicles/${vehicleId}/default`)
  }
}

// 停车记录API
export const parkingRecordApi = {
  // 分页查询停车记录
  getParkingRecordList: (params) => {
    return request.get('/api/parking/records', { params })
  },

  // 获取停车记录详情
  getParkingRecordDetail: (recordId) => {
    return request.get(`/api/parking/records/${recordId}`)
  },

  // 创建停车记录
  createParkingRecord: (data) => {
    return request.post('/api/parking/records', data)
  },

  // 结束停车
  endParking: (recordId) => {
    return request.post(`/api/parking/records/${recordId}/end`)
  },

  // 获取停车统计
  getParkingStatistics: (params) => {
    return request.get('/api/parking/records/statistics', { params })
  }
}

// 停车缴费API
export const parkingPaymentApi = {
  // 分页查询待缴费记录
  getUnpaidRecords: (params) => {
    return request.get('/api/parking/payments/unpaid', { params })
  },

  // 获取缴费详情
  getPaymentDetail: (recordId) => {
    return request.get(`/api/parking/payments/${recordId}`)
  },

  // 创建缴费订单
  createPaymentOrder: (data) => {
    return request.post('/api/parking/payments/orders', data)
  },

  // 支付确认
  confirmPayment: (orderId, data) => {
    return request.post(`/api/parking/payments/orders/${orderId}/confirm`, data)
  },

  // 获取缴费记录
  getPaymentRecords: (params) => {
    return request.get('/api/parking/payments/records', { params })
  },

  // 获取缴费统计
  getPaymentStatistics: (params) => {
    return request.get('/api/parking/payments/statistics', { params })
  }
}

// 充电桩管理API
export const chargingStationApi = {
  // 分页查询充电桩列表
  getChargingStationList: (params) => {
    return request.get('/api/parking/charging-stations', { params })
  },

  // 获取充电桩详情
  getChargingStationDetail: (stationId) => {
    return request.get(`/api/parking/charging-stations/${stationId}`)
  },

  // 查询可用充电桩
  getAvailableChargingStations: (params) => {
    return request.get('/api/parking/charging-stations/available', { params })
  },

  // 预约充电
  reserveCharging: (stationId, data) => {
    return request.post(`/api/parking/charging-stations/${stationId}/reserve`, data)
  },

  // 开始充电
  startCharging: (reservationId) => {
    return request.post(`/api/parking/charging/${reservationId}/start`)
  },

  // 结束充电
  endCharging: (chargingId) => {
    return request.post(`/api/parking/charging/${chargingId}/end`)
  },

  // 获取充电记录
  getChargingRecords: (params) => {
    return request.get('/api/parking/charging/records', { params })
  }
}

// 停车设置API
export const parkingSettingApi = {
  // 获取停车设置
  getParkingSettings: () => {
    return request.get('/api/parking/settings')
  },

  // 更新停车设置
  updateParkingSettings: (data) => {
    return request.put('/api/parking/settings', data)
  },

  // 获取通知设置
  getNotificationSettings: () => {
    return request.get('/api/parking/settings/notifications')
  },

  // 更新通知设置
  updateNotificationSettings: (data) => {
    return request.put('/api/parking/settings/notifications', data)
  },

  // 获取自动缴费设置
  getAutoPaymentSettings: () => {
    return request.get('/api/parking/settings/auto-payment')
  },

  // 更新自动缴费设置
  updateAutoPaymentSettings: (data) => {
    return request.put('/api/parking/settings/auto-payment', data)
  }
}

// 默认导出
export default {
  parkingStatusApi,
  spaceApi,
  vehicleApi,
  parkingRecordApi,
  parkingPaymentApi,
  chargingStationApi,
  parkingSettingApi
}
